﻿using NUnit.Framework;

namespace Agile.Crm4.Plugins.FilteredLookup.Tests
{
    [TestFixture]
    public class LookupSingleTests : FilterLookupTests
    {
        [Test]
        public void Parse_PageUrlWithFilterThatMatchesEntityName_ShouldReturnMatchingFilter()
        {
            var pageReferer = string.Empty;
            var pageUrl = "http://CrmService/OrganizationName/_controls/lookup/lookupsingle.aspx?class=ParentLookup&objecttypes=1,2&browse=0&currentcontact=%7b00000000-0000-0000-0000-000000000000%7d&currentaccount=%7b00000000-0000-0000-0000-000000000000%7d&ShowNewButton=1&ShowPropButton=1&DefaultType=0&filters=" + Filters;
            var adapter = new AdditionalFilterAdapter(Key, EntityName, pageUrl, pageReferer);

            var actual = adapter.GetAdditionalFilter();
            var expected = "<filter><condition attribute=\"firstname\" operator=\"like\" value=\"moti\" /></filter>";

            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void Parse_PageRefererWithFilterThatMatchesEntityName_ShouldReturnMatchingFilter()
        {
            var pageUrl = "http://CrmServer/OrganizationName/AppWebServices/AppGridWebService.asmx";
            var pageReferer = "http://CrmServer/OrganizationName/_controls/lookup/lookupsingle.aspx?class=ParentLookup&objecttypes=1,2&browse=0&currentcontact=%7b00000000-0000-0000-0000-000000000000%7d&currentaccount=%7b00000000-0000-0000-0000-000000000000%7d&ShowNewButton=1&ShowPropButton=1&DefaultType=0&filters=" + Filters;
            var adapter = new AdditionalFilterAdapter(Key, EntityName, pageUrl, pageReferer);

            var actual = adapter.GetAdditionalFilter();
            var expected = "<filter><condition attribute=\"firstname\" operator=\"like\" value=\"moti\" /></filter>";

            Assert.AreEqual(expected, actual);
        }

    }
}
